<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RocketMQ 异常处理完全指南</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        /* 首字下沉效果 */
        .drop-cap::first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            margin-top: 0.5rem;
            font-weight: 700;
            color: #4a5568;
            font-family: 'Noto Serif SC', serif;
        }
        
        /* 代码块美化 */
        pre {
            background: #1a202c;
            color: #e2e8f0;
            border-radius: 0.75rem;
            padding: 1.5rem;
            overflow-x: auto;
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
            position: relative;
        }
        
        pre::before {
            content: attr(data-language);
            position: absolute;
            top: 0.5rem;
            right: 1rem;
            font-size: 0.75rem;
            color: #718096;
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }
        
        /* 卡片悬停效果 */
        .hover-card {
            transition: all 0.3s ease;
        }
        
        .hover-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        
        /* 标题装饰 */
        .section-title {
            position: relative;
            padding-left: 1.5rem;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 100%;
            background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        /* 列表样式 */
        .custom-list li {
            position: relative;
            padding-left: 2rem;
            margin-bottom: 0.75rem;
        }
        
        .custom-list li::before {
            content: '▸';
            position: absolute;
            left: 0;
            color: #667eea;
            font-weight: bold;
            font-size: 1.25rem;
        }
        
        /* 滚动动画 */
        .fade-in {
            opacity: 0;
            transform: translateY(20px);
            animation: fadeIn 0.6s ease forwards;
        }
        
        @keyframes fadeIn {
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        /* 延迟动画 */
        .delay-1 { animation-delay: 0.1s; }
        .delay-2 { animation-delay: 0.2s; }
        .delay-3 { animation-delay: 0.3s; }
        .delay-4 { animation-delay: 0.4s; }
        
        /* Mermaid 图表样式 */
        .mermaid {
            background: white;
            border-radius: 0.75rem;
            padding: 2rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        }
    </style>
</head>
<body>
    <!-- Hero 区域 -->
    <section class="relative overflow-hidden bg-gradient-to-br from-purple-600 via-pink-600 to-red-600 text-white">
        <div class="absolute inset-0 bg-black opacity-20"></div>
        <div class="relative container mx-auto px-6 py-24">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 fade-in">
                    RocketMQ 异常处理
                    <span class="block text-3xl md:text-4xl mt-4 font-light">完全指南</span>
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90 fade-in delay-1">
                    深入理解分布式消息系统的异常处理机制，构建高可用的消息服务
                </p>
                <div class="flex justify-center space-x-6 fade-in delay-2">
                    <div class="text-center">
                        <i class="fas fa-shield-alt text-4xl mb-2"></i>
                        <p class="text-sm">可靠性保障</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-sync-alt text-4xl mb-2"></i>
                        <p class="text-sm">自动恢复</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-chart-line text-4xl mb-2"></i>
                        <p class="text-sm">性能优化</p>
                    </div>
                </div>
            </div>
        </div>
        <div class="absolute bottom-0 left-0 right-0">
            <svg viewBox="0 0 1440 120" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M0 120L60 105C120 90 240 60 360 45C480 30 600 30 720 37.5C840 45 960 60 1080 67.5C1200 75 1320 75 1380 75L1440 75V120H1380C1320 120 1200 120 1080 120C960 120 840 120 720 120C600 120 480 120 360 120C240 120 120 120 60 120H0Z" fill="#f5f7fa"/>
            </svg>
        </div>
    </section>

    <!-- 主要内容区域 -->
    <main class="container mx-auto px-6 py-12 max-w-6xl">
        
        <!-- 概览卡片 -->
        <div class="grid md:grid-cols-3 gap-6 mb-16 fade-in delay-3">
            <div class="bg-white rounded-xl p-6 hover-card">
                <div class="flex items-center mb-4">
                    <div class="w-12 h-12 bg-purple-100 rounded-lg flex items-center justify-center mr-4">
                        <i class="fas fa-paper-plane text-purple-600 text-xl"></i>
                    </div>
                    <h3 class="text-lg font-semibold text-gray-800">发送异常处理</h3>
                </div>
                <p class="text-gray-600">内置重试机制、故障转移、应用层重试策略，确保消息可靠发送</p>
            </div>
            
            <div class="bg-white rounded-xl p-6 hover-card">
                <div class="flex items-center mb-4">
                    <div class="w-12 h-12 bg-blue-100 rounded-lg flex items-center justify-center mr-4">
                        <i class="fas fa-inbox text-blue-600 text-xl"></i>
                    </div>
                    <h3 class="text-lg font-semibold text-gray-800">消费异常处理</h3>
                </div>
                <p class="text-gray-600">消费重试、死信队列、幂等性保证，保障消息正确消费</p>
            </div>
            
            <div class="bg-white rounded-xl p-6 hover-card">
                <div class="flex items-center mb-4">
                    <div class="w-12 h-12 bg-green-100 rounded-lg flex items-center justify-center mr-4">
                        <i class="fas fa-server text-green-600 text-xl"></i>
                    </div>
                    <h3 class="text-lg font-semibold text-gray-800">系统异常恢复</h3>
                </div>
                <p class="text-gray-600">主从切换、数据恢复、消费进度管理，实现系统高可用</p>
            </div>
        </div>

        <!-- 第一部分：消息发送失败的处理策略 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold text-gray-800 mb-8 section-title">消息发送失败的处理策略</h2>
            
            <div class="bg-white rounded-xl p-8 shadow-lg mb-8">
                <p class="text-lg text-gray-700 mb-6 drop-cap">
                    在分布式消息系统中，消息发送失败是不可避免的问题。RocketMQ提供了多种机制来处理消息发送失败的情况，确保消息的可靠传递。
                </p>
                
                <!-- 发送失败原因 -->
                <div class="mb-8">
                    <h3 class="text-2xl font-semibold text-gray-800 mb-6 flex items-center">
                        <i class="fas fa-exclamation-triangle text-yellow-500 mr-3"></i>
                        发送失败的常见原因
                    </h3>
                    
                    <div class="grid md:grid-cols-2 gap-6">
                        <div class="bg-gray-50 rounded-lg p-6">
                            <h4 class="font-semibold text-gray-800 mb-3 flex items-center">
                                <i class="fas fa-network-wired text-red-500 mr-2"></i>
                                网络异常
                            </h4>
                            <ul class="custom-list text-gray-600">
                                <li>网络连接中断或超时</li>
                                <li>网络拥塞导致的数据包丢失</li>
                                <li>DNS解析失败</li>
                            </ul>
                        </div>
                        
                        <div class="bg-gray-50 rounded-lg p-6">
                            <h4 class="font-semibold text-gray-800 mb-3 flex items-center">
                                <i class="fas fa-server text-orange-500 mr-2"></i>
                                Broker异常
                            </h4>
                            <ul class="custom-list text-gray-600">
                                <li>Broker服务不可用</li>
                                <li>Broker磁盘满或IO异常</li>
                                <li>Broker负载过高，响应超时</li>
                            </ul>
                        </div>
                        
                        <div class="bg-gray-50 rounded-lg p-6">
                            <h4 class="font-semibold text-gray-800 mb-3 flex items-center">
                                <i class="fas fa-desktop text-blue-500 mr-2"></i>
                                客户端异常
                            </h4>
                            <ul class="custom-list text-gray-600">
                                <li>客户端配置错误</li>
                                <li>客户端资源不足</li>
                                <li>客户端权限不足</li>
                            </ul>
                        </div>
                        
                        <div class="bg-gray-50 rounded-lg p-6">
                            <h4 class="font-semibold text-gray-800 mb-3 flex items-center">
                                <i class="fas fa-envelope text-purple-500 mr-2"></i>
                                消息异常
                            </h4>
                            <ul class="custom-list text-gray-600">
                                <li>消息体过大</li>
                                <li>消息格式错误</li>
                                <li>消息属性不符合要求</li>
                            </ul>
                        </div>
                    </div>
                </div>
                
                <!-- 内置重试机制 -->
                <div class="mb-8">
                    <h3 class="text-2xl font-semibold text-gray-800 mb-6 flex items-center">
                        <i class="fas fa-redo text-blue-500 mr-3"></i>
                        内置重试机制
                    </h3>
                    
                    <div class="space-y-6">
                        <div class="bg-blue-50 rounded-lg p-6">
                            <h4 class="font-semibold text-gray-800 mb-3">同步发送重试</h4>
                            <pre data-language="java"><code>producer.setRetryTimesWhenSendFailed(3); // 设置重试3次</code></pre>
                            <ul class="custom-list text-gray-600 mt-4">
                                <li>默认重试2次（共3次尝试）</li>
                                <li>通过 <code class="bg-gray-200 px-2 py-1 rounded text-sm">producer.setRetryTimesWhenSendFailed()</code> 设置重试次数</li>
                                <li>重试间隔为固定值，默认为1秒</li>
                            </ul>
                        </div>
                        
                        <div class="bg-green-50 rounded-lg p-6">
                            <h4 class="font-semibold text-gray-800 mb-3">异步发送重试</h4>
                            <pre data-language="java"><code>producer.setRetryTimesWhenSendAsyncFailed(2); //